package com.hzit.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;


/**
 * 作者：李嘉浩
 * 时间：2024-08-22-20:14
 * 功能：
 */


@Configuration
public class MyWebConfig {
    @Bean
    public CorsWebFilter corsWebFilter(){
        UrlBasedCorsConfigurationSource configSource=new UrlBasedCorsConfigurationSource();

        CorsConfiguration config=new CorsConfiguration();
        config.addAllowedHeader("*");
        config.addAllowedMethod("*");
        config.addAllowedOrigin("*");
        config.setAllowCredentials(true);
        configSource.registerCorsConfiguration("/**",config);
        CorsWebFilter corsWebFilter = new CorsWebFilter(configSource);
        return corsWebFilter;
    }
}
